package zjh_20230403_homework;

public class Demo01 implements Cloneable {
    public static void main(String[] args) {
        Computer computer = new Computer();
        computer.name = "DELL";
        computer.price = 9000.0;
        Cpu cpu = new Cpu();
        cpu.name = "i9";
        computer.cpu = cpu;
        System.out.println(computer);

        //浅克隆
//        Computer clone;
//        try {
//            clone = computer.clone();
//            System.out.println(clone);
//        } catch (CloneNotSupportedException e) {
//            throw new RuntimeException(e);
//        }
//        clone.cpu.name = "i7-7000";
//        System.out.println(clone);
//        System.out.println(computer);

        //深克隆
        Computer clone;
        try {
            clone = computer.clone();
            System.out.println(clone);
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
        clone.cpu.name = "i7-7000";
        System.out.println(clone);
        System.out.println(computer);
    }
}
